K = ((0, -1), (1, 0), (0, 1), (-1, 0)) R, C = map(int, input().split()); M = [input() for _ in range(R)]; V = [[0]*C for _ in range(R)]; X = 0 for i in range(R): for j in range(C): if M[i][j] in 'AB': s = [(i, j, 0, 0)]; x = ord(M[i][j])-67 while s: r, c, dr, dc = s.pop() if V[r][c]: continue V[r][c] = x; t = []; n = 0 for di, dj in K: if R>r+di>-1r+dr>-1r+dr>-1r+dr>-1r+dr>-1r+dr>-1r+dr>-10 and A[i][j]>0 and B[i][j]<1; b += V[i][j]>0 and B[i][j]>0 and A[i][j]<1; c += V[i][j]>0 and A[i][j]>0 and B[i][j]>0 print(a, b, c)